package com.sino.dao.hibernate;

import java.net.URLEncoder;
import java.util.Iterator;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sino.bean.Basicinfo;
import com.sino.bean.Xk;
import com.sino.dao.IPatentManageStatDAO;
import com.sino.util.SysParameter;

public class PatentManageStatDAO  extends HibernateDaoSupport implements IPatentManageStatDAO {

	public List findPatentStatAllCount() {
		String sqlSQL="select count(*) from Basicinfo as basicinfo  where basicinfo.year="+SysParameter.CURRENT_YEAR+" order by basicinfo.zlid";
		return this.getHibernateTemplate().find(sqlSQL);
	}


	public String findPatentStatByZlid(String zlid) {
		return ((Basicinfo)this.getHibernateTemplate().get(Basicinfo.class, zlid)).getSbr();
	}


	public List findPatentStatBySbrName(String hpl) {
		return this.getHibernateTemplate().find(hpl);
	}

	public List findPatentStatByQxkw() {
		String sqlSQL="select count(*),b.qxkw.name,b.qxkw.id from Basicinfo as b where b.year="+SysParameter.CURRENT_YEAR+"  group by b.qxkw.id  order by count(*) desc";
		return this.getHibernateTemplate().find(sqlSQL);
	}
	public List findPatentStatByQxkw(String qxkw) {
		String sqlSQL="from Basicinfo as b  where  b.qxkw.id=? and  b.year="+SysParameter.CURRENT_YEAR+" order by b.qxkw.id desc ";
		return this.getHibernateTemplate().find(sqlSQL,qxkw);
	}

	public List findPatentStatBySbr() {
		String sqlSQL="select count(*),b.sbr,b.zlid from Basicinfo as  b  where b.year="+SysParameter.CURRENT_YEAR+" and (length(b.sbr)<16 or b.sbr like '%、%')  group by b.sbr order by count(*) desc";
		return this.getHibernateTemplate().find(sqlSQL);
	}

	public List findPatentStatBySbr(String sbr) {
		String sqlSQL="from Basicinfo as  b  where b.sbr=? and  b.year="+SysParameter.CURRENT_YEAR+" order by b.sbr";
		return this.getHibernateTemplate().find(sqlSQL,sbr);
	}

	public List findPatentStatByZy() {
		String sqlSQL="select count(*),b.xk.name,b.xk.id  from Basicinfo as  b where  b.year="+SysParameter.CURRENT_YEAR+" group by b.xk.id order by count(*) desc";
		return this.getHibernateTemplate().find(sqlSQL);
	}

	public List findPatentStatByZy(String zy) {
		String sqlSQL=" from Basicinfo as  b  where b.xk.id=? and b.year="+SysParameter.CURRENT_YEAR+" order by b.xk.id";
	    return  this.getHibernateTemplate().find(sqlSQL,zy);
	}

	public Xk  findPatentStatById(String  xk) {
		return (Xk)this.getHibernateTemplate().get(Xk.class, xk);
	}

	public List findPatentStatBySbrWithUnit() {
		String sqlSQL="select count(*),b.sbr,b.zlid from Basicinfo as  b where b.year="+SysParameter.CURRENT_YEAR+" and length(b.sbr)>=16 and  b.sbr not like '%、%' group by  b.sbr order by count(*) desc ";
		return this.getHibernateTemplate().find(sqlSQL);
	}

	public List findPatentStatBySbrWithUnit(String sbr) {
		String sqlSQL="from Basicinfo as  b  where b.year="+SysParameter.CURRENT_YEAR+" and b.sbr=? order by b.sbr";
		return this.getHibernateTemplate().find(sqlSQL,sbr);
	}

	public List findPatentStatByQxkw1(String hpl) {
		return this.getHibernateTemplate().find(hpl);
	}

}
